<?php

$html = '<form name="'.$data['summary']['id'].'" method="post" action="http://'.$data['summary']['uri'].'">';

/*
 * Process Recordset Actions
 */

if (isset($data['actions']) && (count($data['actions']) > 0))
{
    $html .= '<div id="content-header">
                <div class="side-a">
                 <img src="Images/icons/48x48-'.$data['summary']['id'].'.png" width="48" height="48" /><span>'.$data['summary']['title'].'</span>
                </div>
              <div class="side-b">
              <input type="hidden" name="'.$data['summary']['id'].'" value="" />';
    
    for ($i = 0, $imax = count($data['actions']); $i < $imax; $i++)
        $html .= '<a href="#" onclick="javascript:document.'.$data['summary']['id'].'.'.$data['summary']['id'].'.value=\''.$data['actions'][$i]['name'].'\';document.'.$data['summary']['id'].'.submit()"><img src="Images/actions/32x32-'.$data['actions'][$i]['name'].'.png" width="32" height="32" /><span>'.$data['actions'][$i]['label'].'</span></a>';        
               
    $html .= '</div></div>';
}

/*
 * Process Recordset Filters and Search Options
 */


    $filters = '';
    
    foreach ($data['filters'] as $k => $v)
    {
    	$filters .= '<select name="rs_'.$data['summary']['id'].'_'.$k.'" onchange="javascript:document.'.$data['summary']['id'].'.submit()">';
    	$filters .= '  <option value=""> - Select '.$v['title'].' - </option>';
    	
    	for ($i = 0, $imax = count($v['data']); $i < $imax; $i++)
    		$filters .= '<option value="'.$v['data'][$i]['value'].'"'.(($v['data'][$i]['selected'] == 'yes')?' selected="selected"':'').'>'.$v['data'][$i]['label'].'</option>';
    	
    	$filters .= '</select>';
    }
    
    $html .= '<div id="content-side-a">
      <div id="recordset">
        <div class="filter">
          <div class="search">
            Filter:
            <input type="text" name="textfield" id="textfield" />
            <input type="submit" name="button" class="button" value="Go!" />
          </div>
          <div class="select">
    		'.$filters.'
          </div>
        </div>';


/*
 * Process Recordset Field Header
 */

$html .= '<table cellpadding="0" cellspacing="0">';

$html .= '<tr>
            <th scope="col" width="25">
              <input name="recordset_selected[]" type="checkbox" value="ALL" />
            </th>';
    
for ($i = 0, $imax = count($data['fields']); $i < $imax; $i++)
    $html .= '<th scope="col" '.((isset($data['fields'][$i]['width']))?'width="'.$data['fields'][$i]['width'].'"':'').'>'.$data['fields'][$i]['label'].'</th>';
    
$html .= '</tr>';

/*
 * Process Recordset Data
 */

if ($data['summary']['total_rows'] > 0)
{
    for ($i = 0, $imax = count($data['data']); $i < $imax; $i++)
    {
        $html .= '<tr'.(($i % 2)?' class="alt-row" ':'').'>';
        $html .= '<td><input name="rs_'.$data['summary']['id'].'_selected[]" type="checkbox" value="'.$data['data'][$i][0].'" /></td>';
        
        for ($x = 0, $xmax = count($data['data'][$i]); $x < $xmax; $x++)
            $html .= '<td>'.$data['data'][$i][$x].'</td>';
            
        $html .= '</tr>';
    }
}
else 
    $html .= '<tr><td colspan="'.(count($data['fields']) + 1).'">No Records</td></tr>';
    
$html .= '</table>';

/*
 * Record Set Pagination
 */

// Pages
for ($i = 0, $imax = $data['summary']['total_pages']; $i < $imax; $i++)
{
	if ($data['summary']['page'] == ($i + 1))
		$pages .= ' '.($i + 1).' ';
	else
		$pages .= '<a href="#" onclick="javascript:document.'.$data['summary']['id'].'.rs_'.$data['summary']['id'].'_page.value=\''.($i + 1).'\';document.'.$data['summary']['id'].'.submit()">'.($i + 1).'</a>';		
}
      
// Start/Previous
if ($data['summary']['page'] > 1)
{
	$start    = '<a href="#" onclick="javascript:document.'.$data['summary']['id'].'.rs_'.$data['summary']['id'].'_page.value=\'1\';document.'.$data['summary']['id'].'.submit()"><img src="Images/recordset/start-active.gif" /></a>';
	$previous = '<a href="#" onclick="javascript:document.'.$data['summary']['id'].'.rs_'.$data['summary']['id'].'_page.value=\''.($data['summary']['page'] - 1).'\';document.'.$data['summary']['id'].'.submit()"><img src="Images/recordset/previous-active.gif" /></a>';	
}	
else
{	
	$start    = '<img src="Images/recordset/start-inactive.gif" />';
	$previous = '<img src="Images/recordset/previous-inactive.gif" />';
}
	
// Next/End
if ($data['summary']['page'] < $data['summary']['total_pages'])
{
	$next = '<a href="#" onclick="javascript:document.'.$data['summary']['id'].'.rs_'.$data['summary']['id'].'_page.value=\''.($data['summary']['page'] + 1).'\';document.'.$data['summary']['id'].'.submit()"><img src="Images/recordset/next-active.gif" /></a>';
	$end  = '<a href="#" onclick="javascript:document.'.$data['summary']['id'].'.rs_'.$data['summary']['id'].'_page.value=\''.$data['summary']['total_pages'].'\';document.'.$data['summary']['id'].'.submit()"><img src="Images/recordset/end-active.gif" /></a>';
}
else 
{
	$next = '<img src="Images/recordset/next-inactive.gif" />';
	$end  = '<img src="Images/recordset/end-inactive.gif" />';
}

$html .= '<div class="info">
      Total Records: '.$data['summary']['total_rows'].' - Displaying Page '.$data['summary']['page'].' of '.$data['summary']['total_pages'].'
    </div>  
    <div class="pagination">
      <input type="hidden" name="rs_'.$data['summary']['id'].'_page" value="" />
      '.$start.'
	  '.$previous.'
      <span class="pages"><span>
		'.$pages.'
      </span></span>
		'.$next.'
		'.$end.' 
    </div>    
  </div> 
</div>
</form>';

return $html;

?>